package com.qiqu.service.impl;

import com.qiqu.entity.Users;
import com.qiqu.dao.UsersDao;
import com.qiqu.service.UsersService;
import org.n3r.idworker.Sid;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;


@Service("usersService")
public class UsersServiceImpl implements UsersService {
    @Resource
    private UsersDao usersDao;
    @Resource
    private Sid sid;

    @Override
    public Users queryById(String id) {
        Users u=new Users();
        u.setId(id);
        System.out.println(usersDao.selectOne(u));
        return usersDao.selectOne(u);
    }

    @Override
    public Users queryByWx(String wx) {
        Example userExample = new Example(Users.class);
        Example.Criteria criteria = userExample.createCriteria();
        criteria.andEqualTo("weixin",wx);
        return usersDao.selectOneByExample(userExample);
    }

    @Override
    public boolean insert(Users users) {
        users.setId(sid.nextShort());
        users.setFansCounts(0);
        users.setFollowCounts(0);
        users.setReceiveLikeCounts(0);
        return usersDao.insert(users)>0;
    }

    @Override
    public Users update(Users users) {
        return null;
    }

    @Override
    public boolean deleteById(String id) {
        return false;
    }

    @Override
    public boolean updateUserFace(Users users) {
        Example userExample = new Example(Users.class);
        Example.Criteria criteria = userExample.createCriteria();
        criteria.andEqualTo("id",users.getId());
        //updateByExampleSelective根据userExample进行更新，其中有的值就更新，没有的就不更新
        return usersDao.updateByExampleSelective(users,userExample)>0;

    }

    @Override
    public boolean updateUser(Users users) {
        return usersDao.updateUser(users);
    }
}